package vn.bus.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import vn.bus.dto.RouteDTO;;

public class RouteDAO {

	public ArrayList<RouteDTO> getAllRoutes(Connection connection) throws Exception
	{
		ArrayList<RouteDTO> allRoutes = new ArrayList<RouteDTO>();
		try
		{
			PreparedStatement ps = connection.prepareStatement("SELECT * FROM routes");
			ResultSet rs = ps.executeQuery();
			while(rs.next())
			{
				RouteDTO Route = new RouteDTO();
				Route.setDistance(rs.getInt("distance"));
				Route.setId(rs.getInt("id"));
				Route.setName(rs.getString("name"));
				Route.setprice1(rs.getInt("price1"));
				Route.setprice2(rs.getInt("price2"));
				allRoutes.add(Route);
			}
			return allRoutes;
		}
		catch(Exception e)
		{
			throw e;
		}
	}
}
